package cn.com.dcsgo.controller;

import cn.com.dcsgo.pojo.User;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * UserController
 *
 * @author Dcsgo
 * @since 2025/3/3 15:53
 */
@RestController
@RequestMapping("user")
public class UserController {

    @GetMapping
    public List<User> getUserByPage(@RequestParam(defaultValue = "1") int pageNum,
                                    @RequestParam(defaultValue = "10") int pageSize) {
        return List.of(
                new User(1L, "DCSGO", 18),
                new User(2L, "dcsgo", 22),
                new User(3L, "DCS", 24)
        );
    }

    @PostMapping
    public String addUser(@RequestBody User user) {
        return "add User: " + user + "Ok";
    }

    @GetMapping("{id}")
    public User getUserById(@PathVariable Long id) {
        return new User(id, "DCSGO", 18);
    }

    @PutMapping
    public User updateUser(@RequestBody User user) {
        return user;
    }

    @DeleteMapping("{id}")
    public String deleteUser(@PathVariable Long id) {
        return "delete User: " + id + "Ok";
    }

    @GetMapping("search")
    public List<User> searchUser(@RequestParam(defaultValue = "1") int pageNumber,
                                 @RequestParam(defaultValue = "10") int pageSize,
                                 @RequestParam String keyword) {
        return List.of(
                new User(1L, "AAA" + keyword, 18),
                new User(2L, keyword + "BBB", 22),
                new User(3L, "CC" + keyword + "C", 24)
        );
    }

}
